namespace diqizhou {
    // 定义 Vehicle 类
    class Vehicle {
        // 公共属性
        public brand: string;
        public year: number;
        // 私有方法
        private isYearValid(year: number): boolean {
            const currentYear = new Date().getFullYear();
            return year <= currentYear;
        }
        // 静态属性
        static vehicleCount: number = 0;
        // 构造函数
        constructor(brand: string, year: number) {
            this.brand = brand;
            this.year = year;
            if (!this.isYearValid(year)) {
                throw new Error('Year of production cannot be in the future.');
            }
            Vehicle.incrementVehicleCount();
        }
        // 实例方法
        getInfo(): string {
            return `Brand: ${this.brand}, Year: ${this.year}`;
        }

        // 静态方法
        static incrementVehicleCount(): void {
            Vehicle.vehicleCount++;
        }
    }
    class Car extends Vehicle {
        private _mileage: number
        constructor(brand: string, year: number, mileage: number) {
            super(brand, year)
            this._mileage = mileage

        }

        get mileage(): number {
            return this._mileage;
        }

        set mileage(value: number) {
            this._mileage = value;
        }


        drive(miles: number): void {
            this.mileage += miles;
        }
        getInfo(): string {
            return `${super.getInfo()}, Mileage: ${this.mileage}`;

        }
        static compareMileage(car1: Car, car2: Car): Car {
            return car1.mileage > car2.mileage ? car1 : car2

        }
    }

    // 调用
    let car1 = new Car('比亚迪', 2020, 15000);
    let car2 = new Car('特斯拉', 2021, 12000);

    car1.drive(500);

    console.log(`里程数较大的是${Car.compareMileage(car1, car2)}`);

    Vehicle.incrementVehicleCount()
    console.log(`现在有${Vehicle.vehicleCount}辆车`);

}